package Logic;

import java.lang.reflect.Method;
import java.util.HashMap;

public class CommandCenter {
    private static HashMap<CommandId, CommandProcessor> commandProcessorMap = new HashMap<>();

    public static void Dispatch(BaseCommand bc) throws  Exception {
        CommandProcessor cp = commandProcessorMap.get(bc.ID);
        if (cp != null) {
            Method method = cp.o.getClass().getMethod(cp.methodName, BaseCommand.class);
            method.invoke(cp.o, bc);
        }
    }

    public static void RegisterCommandProcessor(CommandId id, Object o, String methodName) {
        CommandProcessor cp = new CommandProcessor(o, methodName);
        commandProcessorMap.put(id, cp);
    }
}
